package com.dotc.kotlinmvvmdemo.viewModel

import android.app.Activity
import android.app.Application
import android.content.Intent
import android.util.Log
import android.view.View
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableDouble
import androidx.databinding.ObservableField
import androidx.databinding.ObservableShort
import com.dotc.kotlinmvvmdemo.base.BaseViewModel
import com.dotc.kotlinmvvmdemo.newPackage.NewMainActivity


/**
 * 主页面NewMainViewModel
 */
class BindingViewModel(application: Application) : BaseViewModel(application) {
    var  context :Activity? = null
    val TAG = "LUO"
    //可以动态更新改值
    val modelKey = ObservableField<String>("----默认值------")
    //控制背景显示，true显示，false不显示
    var visibleBg = ObservableField<Boolean>(false)
    //只接受初始化的值，不可以动态更新改值
    var modelDay = "这是中国"
    var list = arrayListOf<String>("中国","美国","日本","英国")
    val listBean = ObservableField<MutableList<String>>(list)

    //--------直接指定类型-----------
    var b1 = ObservableBoolean(false)
    var b2 = ObservableDouble(1.2)



    init {
        //只初始化一次
        visibleBg.set(false)
    }


    /**
     * 更改背景值
     */
    fun click2(view: View){
        if (visibleBg.get() == true){
            visibleBg.set(false)
        }else{
            visibleBg.set(true)
        }

    }

    /**
     * 更改modelDay的值
     */
    var index = 0
    fun click3(){
        modelKey.set("今天见到你，很开心；${++index}")
    }


}